<?php

namespace App\V3\V3_2_7\Controllers;

use App\Http\Controllers\Controller;
use App\Http\Requests\V3_2_7\ShelfLocationTagRequest;
use App\Http\Requests\V3_2_7\VerifyIdRequest;
use App\V3\V3_2_7\Services\ShelfLocationTagService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ShelfLocationTagController extends BaseController
{

    /**
     *列表
     * Author: zlf
     * Created at 2024/9/5 11:27
     * @param Request $request
     * @return JsonResponse
     */
    public function index(Request $request): JsonResponse
    {
        $data = $request->all();
        if ($this->getMainUserId() !== 1) {
            return $this->fail('', '您无权限操作！');
        }
        return $this->success(ShelfLocationTagService::list($data));
    }

    /**
     *创建仓库、库位标签
     * Author: zlf
     * Created at 2024/9/4 17:12
     * @param ShelfLocationTagRequest $request
     * @return JsonResponse|null
     */
    public function create(ShelfLocationTagRequest $request): ?JsonResponse
    {
        $data = $request->all();
        if ($this->getMainUserId() !== 1) {
            return $this->fail('', '您无权限操作！');
        }
        $time = time();
        $data['main_id'] = $this->getMainUserId();
        $data['user_id'] = $this->getUserId();
        $this->operateLog('创建货架、库位标签', $data, $time);
        return ShelfLocationTagService::add($data, $time);
    }


    /**
     *查询信息
     * Author: zlf
     * Created at 2024/9/5 11:02
     * @param VerifyIdRequest $request
     * @return JsonResponse
     */
    public function show(VerifyIdRequest $request): JsonResponse
    {
        $data = $request->all();
        if ($this->getMainUserId() !== 1) {
            return $this->fail('', '您无权限操作！');
        }
        return $this->success(ShelfLocationTagService::info($data));
    }

    /**
     *修改货架、库位标签
     * Author: zlf
     * Created at 2024/9/5 10:34
     * @param ShelfLocationTagRequest $request
     * @return JsonResponse|null
     */
    public function update(ShelfLocationTagRequest $request)
    {
        $data = $request->all();
        if ($this->getMainUserId() !== 1) {
            return $this->fail('', '您无权限操作！');
        }
        if (empty($data['id'])) {
            return $this->fail('', '标签主键，不能为空！');
        }
        if (!is_int((int)$data['id'])) {
            return $this->fail('', '标签主键，为整数！');
        }
        $time = time();
        $data['user_id'] = $this->getUserId();
        $this->operateLog('修改货架、库位标签', $data, $time);
        return ShelfLocationTagService::upd($data, $time);
    }

    /**
     *删除
     * Author: zlf
     * Created at 2024/9/5 11:14
     * @param VerifyIdRequest $request
     * @return JsonResponse
     */
    public function destroy(VerifyIdRequest $request): JsonResponse
    {

        $data = $request->all();
        if ($this->getMainUserId() !== 1) {
            return $this->fail('', '您无权限操作！');
        }
        return $this->fail('', '删除功能，暂时不能开放！');
        $time = time();
        $data['user_id'] = $this->getUserId();
        $this->operateLog('修改货架、库位标签', $data, $time);
        return ShelfLocationTagService::del($data, $time);
    }

    /**
     *列表
     * Author: zlf
     * Created at 2024/9/5 11:27
     * @param Request $request
     * @return JsonResponse
     */
    public function getTagList(Request $request): JsonResponse
    {
        $data = $request->all();
        return $this->success(ShelfLocationTagService::tagList($data));
    }
}
